package com.star.comtroller;

import com.star.entry.User;
import com.star.service.UserService;
import com.star.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SuppressWarnings("all")
@RestController
@RequestMapping("/user/")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ResultObject result;

    @RequestMapping("register")
    public ResultObject add(User user) {
        boolean b = userService.insert(user);
        if (b) {
            result.setStatus(400);
            result.setResult("注册成功");
        } else {
            result.setStatus(406);
            result.setResult("注册失败");
        }
        return result;
    }

    @RequestMapping("login")
    public ResultObject login(User user) {
        boolean b = userService.select(user) != null;
        System.out.println("zjheloiesjfa1:"+b);
        if (b) {
            result.setStatus(400);
            result.setResult("登录成功");
        } else {
            result.setStatus(406);
            result.setResult("登录失败");
        }
        return result;
    }

    @RequestMapping("renew")
    public ResultObject yanzheng(User user) {
        User user1 = userService.selectForgot(user);
        result.setResult(user1);
        result.setStatus(400);
        return result;
    }

    @RequestMapping("mima")
    public ResultObject mima(User user) {
        boolean b = userService.update(user);
        if (b) {
            result.setStatus(400);
            result.setResult("修改成功");
        } else {
            result.setStatus(406);
            result.setResult("修改失败");
        }
        return result;
    }
}